package com.muheda.notice.kafka;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;
import org.apache.kafka.common.PartitionInfo;

import java.util.List;
import java.util.Map;

public class AeraPartitioner implements Partitioner {
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        System.out.println("分区器被调用了");

        // 定义分区号
        int pumn = 0;
        String value1 = (String) value;
        List<PartitionInfo> partitionInfos = cluster.availablePartitionsForTopic(topic);
        pumn = value1.contains("0410")?0:partitionInfos.size()-1;
        System.out.println("分区号"+pumn);
        System.out.println("主题"+topic);


        return pumn;
    }

    @Override
    public void close() {
        System.out.println("分区器关闭");

    }

    @Override
    public void configure(Map<String, ?> configs) {

        System.out.println("分区器配置");
    }



}

